package com.woniu.pay.config;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import com.woniu.pay.constant.AliPayInfoConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AliClientConfig {

    @Bean
    public AlipayClient alipayClient() throws AlipayApiException {
        AlipayConfig alipayConfig = new AlipayConfig();
        // 设置网关地址
        alipayConfig.setServerUrl(AliPayInfoConstants.SERVER_URL);
        //设置应用Id
        alipayConfig.setAppId(AliPayInfoConstants.App_Id);
        //设置应用私钥
        alipayConfig.setPrivateKey(AliPayInfoConstants.PRIVATE_KEY);
        //设置请求格式，固定值JSON
        alipayConfig.setFormat(AliPayInfoConstants.FORMAT);
        //设置字符集
        alipayConfig.setCharset(AliPayInfoConstants.CHARSET);
        //设置支付宝公钥
        alipayConfig.setAlipayPublicKey(AliPayInfoConstants.ALIPAY_PUBLIC_KEY);
        //设置签名类型
        alipayConfig.setSignType(AliPayInfoConstants.SIGN_TYPE);
        AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);
        return alipayClient;
    }
}
